<?php
if (! $canAccess) {
	$AppUI->setMsg('Access denied', UI_MSG_ERROR);
	$AppUI->redirect();
}
$search_str;
$type;

// To configure an aditional filter to use in the search string
if(isset($_REQUEST['code'])){
	$search_str = $_REQUEST['code'];
}

if(isset($_REQUEST['type'])){
	$type = $_REQUEST['type'];
}

// get type list
require_once(DP_BASE_DIR."/modules/masterdata/mdtype.class.php");

$q= new DBQuery();
$q->addTable('suppliers');
$q->addJoin('divisions','','div_id = sup_id');
if($search_str!= null && $search_str != ''){
	$q->addWhere('sup_code like \'%'.$search_str.'%\'');
}
if($type!= null && $type!= ''){
	$q->addWhere('sup_type ='.$type);
}
$q->addOrder('sup_name');
$suppliers = $q->loadList();

	header('Content-Type: text/xml');

	$xml = new XmlWriter();
	$xml->openMemory();
	$xml->startDocument('1.0', 'UTF-8');
	
	$xml->startElement('root');
	
	obj2xml($xml, 'suppliers', 'supplier', $suppliers);
	
	$xml->endElement();
	
	echo $xml->outputMemory(true);
?>